package com.prs.crm.dao.oa.impl;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.context.AppContext;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.oa.CheckWorkDao;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Apply;
import com.prs.crm.domain.oa.CheckWork;

public class CheckWorkDaoImpl extends BaseDaoImpl<CheckWork> implements CheckWorkDao{

	@SuppressWarnings("unchecked")
	@Override
	public CheckWork getCheckWorkByPerson(Person person){
		Criteria criteria = this.getSession().createCriteria(CheckWork.class);
		criteria.add(Restrictions.eq("recorder", person));
		Date mydate=new Date();
		DateFormat f=DateFormat.getDateInstance();
		String d=f.format(mydate);
		List<CheckWork> list=criteria.list();
		if(list.size()!=0){
			List<CheckWork> cs=null;
			for(int i=0;i<list.size();i++){
				CheckWork c=list.get(i);
				String d2=f.format(c.getRecordTime());
				if(d.equals(d2)){
					return c;
				}
				
			}
		}
		return null;
	}

	@Override
	public CheckWork getCode(final String name,final Integer persons) {
		Criteria criteria = this.getSession().createCriteria(CheckWork.class);
		criteria.add(Restrictions.eq("code", name));
		criteria.add(Restrictions.eq("persons", AppContext.getAccountContext().currentUser().getId()));
		List result=criteria.list();
		if (result==null || result.size()==0) {
			return null;
		}
		return (CheckWork) result.get(0);
	}

}
